﻿using System;
using System.Collections.Generic;
using System.Text;

namespace TimeCheque
{
    public class WorkItem
    {
        #region private variables
        List<WorkUnit> workunits;
        WorkUnit currentWorkItem;

        #endregion


        public string Name { get; set; }
        public TimeSpan Estimate { get; set; }


        public WorkItemStatus WorkItemStatus
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public decimal CostPerUnit { get; set; }



        public Currency Currency
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public List<WorkUnit> WorkUnits
        {
            get
            {
                if (workunits == null)
                {
                    workunits = new List<WorkUnit>();
                }

                return workunits;
            }
            set
            {
                workunits = value;
            }
        }

        public bool IsWorking
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public TimeSpan TotalElaspedTime
        {
            get
            {
                TimeSpan ts = new TimeSpan();
                foreach (WorkUnit wu in WorkUnits)
                {
                    ts.Add(wu.ElaspedTime);
                }
                return ts;
            }
        }

        public int WorkItemID
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public decimal TotalCost
        {
            get
            {
                return Convert.ToDecimal( Convert.ToDouble (this.CostPerUnit) * Convert.ToDouble( this.TotalElaspedTime.TotalHours));
            }
        }


        public bool WorkUnitStart(User User)
        {
            currentWorkItem = new WorkUnit();
            currentWorkItem.TimeStart = DateTime.Now;
            WorkUnits.Add(currentWorkItem);
            return true;
        }

        public bool WorkUnitStop()
        {
            currentWorkItem.TimeEnd = DateTime.Now;
            return true;

        }
    }
}
